package com.ark.frigate.zookeeper.state;

import org.springframework.messaging.Message;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author ZengWeiLong
 * @Description Copy Right Beyonca
 * @Date 2022/3/25 20:21
 * @Version 1.0
 */
@Slf4j
@WithStateMachine(id = "orderMachine")
public class OrderEventConfig {

    /**
     * 当前状态UNPAID
     */
    @OnTransition(target = "UNPAID")
    public void create() {
        log.info("---订单创建，待支付---");
    }

    /**
     * UNPAID->WAITING_FOR_RECEIVE 执行的动作
     */
    @OnTransition(source = "UNPAID", target = "WAITING_FOR_RECEIVE")
    public void pay(Message<OrderEvents> message) {
        System.out.println("传递的参数：" + message.getHeaders().get("order"));
        log.info("---用户完成支付，待收货---");
    }

    /**
     * WAITING_FOR_RECEIVE->DONE 执行的动作
     */
    @OnTransition(source = "WAITING_FOR_RECEIVE", target = "DONE")
    public void receive(Message<OrderEvents> message) {
        System.out.println("传递的参数：" + message.getHeaders().get("order"));
        System.out.println("传递的参数：" + message.getHeaders().get("otherObj"));
        log.info("---用户已收货，订单完成---");
    }
}
